package com.ji.zhiqu.controller;

import com.ji.zhiqu.common.BaseResponse;
import com.ji.zhiqu.common.ErrorCode;
import com.ji.zhiqu.common.ResultUtils;
import com.ji.zhiqu.exception.ThrowUtils;
import com.ji.zhiqu.mapper.UserAnswerMapper;
import com.ji.zhiqu.model.dto.statistic.AppAnswerCountDTO;
import com.ji.zhiqu.model.dto.statistic.AppAnswerResultCountDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * App统计分析接口
 */
@RestController
@RequestMapping("/app/statistic")
@Slf4j
public class AppStatisticController {

    @Resource
    private UserAnswerMapper userAnswerMapper;

    /**
     * 按用户答题数量统计热门app
     * @return
     */
    @GetMapping("/answer_count")
    public BaseResponse<List<AppAnswerCountDTO>> getAppAnswerCount(){
        List<AppAnswerCountDTO> appAnswerCountDTOS = userAnswerMapper.doAppAnswerCount();
        return ResultUtils.success(appAnswerCountDTOS);
    }


    /**
     * 统计某个app的用户答案结果
     * @param appId
     * @return
     */
    @GetMapping("/answer_result_count")
    public BaseResponse<List<AppAnswerResultCountDTO>> getAppAnswerResultCount(Long appId){
        ThrowUtils.throwIf(appId == null || appId <= 0, ErrorCode.PARAMS_ERROR);
        List<AppAnswerResultCountDTO> appAnswerResultCountDTOS = userAnswerMapper.doAnswerResultCount(appId);
        return ResultUtils.success(appAnswerResultCountDTOS);
    }
}
